class Post < ApplicationRecord
  validates :title, presence: true, length: { maximum: 50 }
  validates :content, presence: true

  after_commit :create_history

  belongs_to :user
  has_many :post_histories

  private

  def create_history
    history = self.post_histories.build(title: self.title, content: self.content)
    history.save
  end

end
